/*
 * 深圳市灵智数科有限公司版权所有.
 */
package com.spring.bean.definition;

import com.spring.bean.definition.domain.User;
import com.spring.bean.definition.factory.UserFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * 功能说明
 *
 * @author 程健
 * @version 1.0.0
 * @date 2020/12/13
 */
public class BeanInstantiationDemo {

    public static void main(String[] args) {
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("bean-instantiation.xml");

        //User user = beanFactory.getBean("user-by-static-method",User.class);

        //System.out.println("user:"+user);

        seviceLoaderDemo();
    }

    /**
     * serviceLoader演示
     */
    public static void seviceLoaderDemo(){
        ServiceLoader<UserFactory> serviceLoader = ServiceLoader.load(UserFactory.class,Thread.currentThread().getContextClassLoader());
        Iterator<UserFactory> iterator = serviceLoader.iterator();
        while(iterator.hasNext()){
            UserFactory user = iterator.next();
            System.out.println(user.createUser());
        }
    }
}